import os
import re

# 测试使用
print(os.path.abspath(__file__))  # 显示当前文件的地址
print(os.getcwd())  # 显示主程序入口的地址


def index(info):
    with open(info["template"] + "/index.html", encoding="utf-8") as f:
        content = f.read()
        content = re.sub(r"\{%content%\}", info["content"], content)
        return content


def center(info):
    with open(info["template"] + "/center.html", encoding="utf-8") as f:
        content = f.read()
        content = re.sub(r"\{%content%\}", info["content"], content)
        return content


def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html;charset=utf-8')])
    filename = environ["PATH_INFO"]
    if filename == "/index.py":
        return index(environ["info"])
    elif filename == "/center.py":
        return center(environ["info"])
    else:
        return '我是一个python文件'.encode("utf-8")
